Skip to content

fix(agent-session): send prompts to sessions with no on-disk transcript yet - #183

Merged
kahme247 merged 1 commit into
ompweb-dev:mainfrom
utsmok:fix/send-without-session-file
Oct 2, 2026
Merged

kahme247 merged 1 commit into
ompweb-dev:mainfrom
utsmok:fix/send-without-session-file

Conversation

@utsmok

@utsmok utsmok commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

A session whose prompts were all local slash commands, such as /skill:poteto-mode, never starts an agent run, so omp writes no session file. Any later send read the transcript boundary from disk, got a 404, and threw before the prompt was dispatched. You saw Failed to send message: HTTP 404, the session looked dead, and follow-up messages were dropped.

Changes

snapshotRunEntries now treats that 404 as an empty baseline and lets the send proceed. loadSession in the same file already tolerates the missing file the same way, so this brings the boundary read in line with it.

Test

New regression case in useAgentSession.rpc.test.mjs: a session that answers /api/agent/<id> but has no session file still dispatches the prompt, with no error notice. Full suite passes (99 tests).

…pt yet

A session whose prompts were all local slash commands never started an
agent run, so omp writes no session file. snapshotRunEntries threw on the
404 from the boundary read, which sits before prompt dispatch, so the
send failed with 'HTTP 404' and follow-up messages were dropped.

Treat that 404 as an empty baseline, the same way loadSession already
tolerates the missing file. Add a regression test.
@kahme247

kahme247 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the report — this is a good catch on a real failure mode, and the fix itself is exactly the right shape. Two notes before I merge, one of which is about the description rather than the code.

What I verified

I re-derived your repro against today's main and it no longer reproduces. The bug you hit was already fixed by #165 (now merged), which answers boundary=1 with 200 {entryIds: []} for a live wrapper whose session file does not exist yet — see app/api/sessions/[id]/context/route.ts:71-73. So the all-slash-command-session case you describe now dispatches fine on main; you almost certainly hit a pre-#165 build.

That is not a reason to close this, because it still closes a narrower hole that really is live: when the session file exists but cannot be read or resolved, that route returns 404 session_file_malformed at :97, before #165's fileless branch gets a chance to apply — while app/api/agent/[id]/route.ts:49 happily dispatches on the live wrapper. A truncated or mid-write header hits this. Your client-side 404 -> [] is exactly the missing piece there, and it composes with #165 rather than replacing it.

I also confirmed the things that usually break in this file: runPreviousEntryIdsRef.current = previousEntryIds is still inside the if (promptRunIdRef.current === promptRunId) fence, so no stale run can be adopted, and returning [] is the conservative direction for finishPromptWithoutStream. Only 404 is swallowed — 413 and 500 still throw, and a genuinely missing session still fails loudly with the text restored to the input. Verified with tests.

Two things worth knowing

The comment overclaims. "There is no prior run to diff against" is not true for every 404 — session_file_malformed can hit a session that does have history. The practical consequence is at hooks/useAgentSession.ts:436-439: with an empty baseline the catch-up heuristic treats every history user message as new, which clears the optimistic user bubble early. On the genuinely fileless session that is the intended behaviour; on a malformed-file session with history, your just-sent message can blink out until the stream renders it. Harmless, but worth a sentence in the description.

The regression test models a state the server cannot produce. It stubs the boundary fetch as 404 while the harness's /api/agent stub succeeds for any unknown session id — the real route 404s with session_not_found (app/api/agent/[id]/route.ts:64). In a faithful harness that test would pass with or without the fix. Installing a real wrapper via attachNativeWrapper and making session_file_malformed the only failure cause would pin the case you actually cover. Not blocking — I am adding tests that exercise it properly on main — but it would be good to tighten it on your side.

Merging the code as it stands.

@kahme247 kahme247 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client-side 404 -> empty-baseline fallback closes a real hole that merged #165 does not cover (session file exists but is unreadable -> session_file_malformed). Fencing intact, real failures still surface. Details in my comment above.

@kahme247
kahme247 merged commit d583b7c into ompweb-dev:main Oct 2, 2026
3 checks passed
kahme247 added a commit that referenced this pull request Oct 2, 2026
Merged #183 turns a 404 from the boundary read into an empty baseline so a
prompt is still dispatched. Its own regression test stubs a state the server
cannot produce -- the harness's /api/agent stub succeeds for any unknown id,
which the real route never does -- so it does not actually pin the fix.

These three do:
- the fileless live session that merged #165 already answers 200, proven on
  the unfixed source, so the original repro no longer exists;
- a 404 boundary on a live session (unreadable file, or a wrapper that died
  between get_state and the read) still dispatches, which is the case #183
  genuinely closes;
- a vanished session with no wrapper still fails loudly, so the new fallback
  did not swallow a real error.
kahme247 added a commit that referenced this pull request Oct 2, 2026
Merged #183 turns a 404 from the boundary read into an empty baseline so a
prompt is still dispatched. Its own regression test stubs a state the server
cannot produce -- the harness's /api/agent stub succeeds for any unknown id,
which the real route never does -- so it does not actually pin the fix.

These three do:
- the fileless live session that merged #165 already answers 200, proven on
  the unfixed source, so the original repro no longer exists;
- a 404 boundary on a live session (unreadable file, or a wrapper that died
  between get_state and the read) still dispatches, which is the case #183
  genuinely closes;
- a vanished session with no wrapper still fails loudly, so the new fallback
  did not swallow a real error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants